/*
 * Created by SharpDevelop.
 * User: michaelo
 * Date: 18/05/2005
 * Time: 19:18
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */

using System;
using System.Drawing;
using System.Windows.Forms;
using System.Collections;
using System.Text.RegularExpressions;
using Orz.LogManager.Config;


namespace Orz.LogManager
{
	/// <summary>
	/// Description of EditLogFile.
	/// </summary>
	public class EditLogFileForm : System.Windows.Forms.Form
	{
		private System.ComponentModel.IContainer components;
		private System.Windows.Forms.GroupBox groupBox3;
		private System.Windows.Forms.Label label6;
		private System.Windows.Forms.Button cmdOK;
		private System.Windows.Forms.RadioButton optTelnet;
		private System.Windows.Forms.Button cmdNewMatch;
		private System.Windows.Forms.GroupBox groupBox2;
		private System.Windows.Forms.GroupBox groupBox1;
		private System.Windows.Forms.Button cmdMatchUp;
		private System.Windows.Forms.RadioButton optLocal;
		private System.Windows.Forms.RadioButton optSSH;
		private System.Windows.Forms.ListView lvwAutoLogins;
		private System.Windows.Forms.Button cmdCancel;
		private System.Windows.Forms.TextBox txtHost;
		private System.Windows.Forms.ColumnHeader colActions;
		private System.Windows.Forms.Label label3;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.Button cmdAutoLoginDelete;
		private System.Windows.Forms.Label label5;
		private System.Windows.Forms.Label label4;
		private System.Windows.Forms.ColumnHeader colSend;
		private System.Windows.Forms.Button cmdAutoLoginNew;
		private System.Windows.Forms.ImageList imageList1;
		private System.Windows.Forms.ListView lvwMatches;
		private System.Windows.Forms.Label lblUsername;
		private System.Windows.Forms.Button cmdAutoLoginUp;
		private System.Windows.Forms.Button cmdDeleteMatch;
		private System.Windows.Forms.Button cmdAutoLoginEdit;
		private System.Windows.Forms.TextBox txtLocalPath;
		private System.Windows.Forms.Button cmdEditMatch;
		private System.Windows.Forms.OpenFileDialog openFileDialog1;
		private System.Windows.Forms.GroupBox grpLocal;
		private System.Windows.Forms.TextBox txtTailCommand;
		private System.Windows.Forms.Label lblUsernameAndPassword;
		private System.Windows.Forms.TextBox txtDisplayName;
		private System.Windows.Forms.ColumnHeader colMatch;
		private System.Windows.Forms.TextBox txtTelnetPath;
		private System.Windows.Forms.Button cmdImport;
		private System.Windows.Forms.ColumnHeader colWaitFor;
		private System.Windows.Forms.Button cmdAutoLoginDown;
		private System.Windows.Forms.Button cmdLocalBrowse;
		private System.Windows.Forms.TextBox txtUsername;
		private System.Windows.Forms.GroupBox grpTelnet;
		private System.Windows.Forms.Button cmdMatchDown;
		
		
		
		private logsetLogfile original_i;
		private logsetLogfile working_i;
		private bool bWasCancelled_i;
		
		private HelpForm help_i;
		
		private const int IMG_CLEARTEXT = 0;
		private const int IMG_ENCRYPTED = 1;
		
		
		
		public EditLogFileForm (logsetLogfile file_p)
		{
			InitializeComponent();
			
			original_i = file_p;
			
			// Make a backup of the working set before we start
			working_i = LogsetLoader.CloneLogfile (original_i);
			
			help_i = new HelpForm (this);
			
			PopulateFields();		
		}
		
		
		
		
		public bool WasCancelled
		{
			get { return bWasCancelled_i; }
		}
		
		
		
		
		private void PopulateFields ()
		{			
			lvwAutoLogins.Items.Clear();
			lvwMatches.Items.Clear();
			
			txtDisplayName.Text = working_i.name;
			
			if (LogsetLoader.isSSH (working_i))
			{
				optSSH.Checked = true;
			}
			else if (LogsetLoader.isTelnet (working_i))
			{
				optTelnet.Checked = true;
			}
			else
			{
				optLocal.Checked = true;
			}
				
			
			txtLocalPath.Text = working_i.path;
			
			txtTelnetPath.Text = working_i.path;
			txtHost.Text = working_i.telnetHost;
			
			if (working_i.telnetPort > 0)
			{
				txtPort.Text = "" + working_i.telnetPort;
			}
			else
			{
				txtPort.Text = "";
			}
			
			
			txtTailCommand.Text = working_i.telnetCommand;
			txtUsername.Text = working_i.sshUsername;
			
			switch (working_i.sshAuthMechanism)
			{
				case sshAuthMechanismType.publicKey:
					cboAuthMechanism.SelectedIndex = 1;
					break;
					
				case sshAuthMechanismType.storePasswordInsecure:
					cboAuthMechanism.SelectedIndex = 2;
					break;
					
				default:
					cboAuthMechanism.SelectedIndex = 0;
					break;
			}
			
			txtSshPassword.Text = "";
			
			if (null != working_i.sshEncryptedPassword  &&  working_i.sshEncryptedPassword.Length > 0)
			{
				txtSshPassword.Text = PasswordHelper.Decrypt(working_i.sshEncryptedPassword);
			}
			
			chkRegex.Checked = working_i.localPathRegex.Length > 0;
			txtRegex.Text = working_i.localPathRegex;
			
			radMultipleMatchesChooseFirst.Checked = (multipleFileMatchStrategyType.chooseFirst == working_i.multipleFileMatchStrategy);
			radMultipleMatchesChooseLast.Checked =  (multipleFileMatchStrategyType.chooseLast == working_i.multipleFileMatchStrategy);
			radMultipleMatchesChooseMostRecent.Checked = (multipleFileMatchStrategyType.chooseMostRecent == working_i.multipleFileMatchStrategy);
						
			PopulateAutoLoginList();			
			PopulateMatchesList();			
		}
		
		
		
		
		private void PopulateAutoLoginList()
		{
			lvwAutoLogins.Items.Clear();
			
			IEnumerator e = working_i.autoLogin.GetEnumerator();
			
			while (e.MoveNext())
			{
				
				logsetLogfileAutoLogin al = (logsetLogfileAutoLogin) e.Current;
				
				int iImageIndex = al.send.encrypted ? IMG_ENCRYPTED : IMG_CLEARTEXT;
				
				ListViewItem item = lvwAutoLogins.Items.Add(al.pattern, iImageIndex);
				
				if (al.send.encrypted)
				{
					item.SubItems.Add ("(encrypted)");
				}
				else
				{
					item.SubItems.Add(al.send.Value);
				}
			}
			
			if (lvwAutoLogins.Items.Count > 0)
			{
				lvwAutoLogins.SelectedItems.Clear();
				lvwAutoLogins.Items[0].Selected = true;				
			}
			
			UpdateButtons();
		}
		
		
		
		
		private void PopulateMatchesList()
		{
			lvwMatches.Items.Clear();
			
			IEnumerator e = working_i.match.GetEnumerator();
			
			while (e.MoveNext())
			{
				logsetLogfileMatch match = (logsetLogfileMatch) e.Current;
				
				string sPatternDescription = (match.pattern.negated ? "NOT " + match.pattern.Value : match.pattern.Value);
				
				ArrayList actions = new ArrayList();
				
				if (match.dontPrint)
				{
					actions.Add ("Don't print");
				}
				
				if (null != match.colour)
				{
					actions.Add ("Colour [" + match.colour + "]");
				}
				
				if (null != match.replacement)
				{
					actions.Add ("Replace with [" + match.replacement + "]");
				}
				
				string sActionsDescription = JoinStringArray(actions, ", ");
				
				ListViewItem item = lvwMatches.Items.Add(sPatternDescription);	
								
				item.SubItems.Add (sActionsDescription);
			}
			
			if (lvwMatches.Items.Count > 0)
			{
				lvwMatches.SelectedItems.Clear();
				lvwMatches.Items[0].Selected = true;				
			}
			
			UpdateButtons();
		}
		
		
		
		
		
		
		private void UpdateButtons ()
		{			
			txtRegex.Enabled = chkRegex.Checked;
			
			bool isOnlyOneMatchSelected = (1 == lvwMatches.SelectedItems.Count);
			bool isAtLeastOneMatchSelected = (lvwMatches.SelectedItems.Count > 0);
		
			cmdEditMatch.Enabled = isOnlyOneMatchSelected;
			cmdDeleteMatch.Enabled = isAtLeastOneMatchSelected;
			cmdMatchUp.Enabled = isOnlyOneMatchSelected;
			cmdMatchDown.Enabled = isOnlyOneMatchSelected;
						
			bool isOnlyOneAutoLoginSelected = (1 == lvwAutoLogins.SelectedItems.Count);
			bool isAtLeastOneAutoLoginSelected = (lvwAutoLogins.SelectedItems.Count > 0);
						
			cmdAutoLoginEdit.Enabled = isOnlyOneAutoLoginSelected;
			cmdAutoLoginDelete.Enabled = isAtLeastOneAutoLoginSelected;
			cmdAutoLoginUp.Enabled = isOnlyOneAutoLoginSelected;
			cmdAutoLoginDown.Enabled = isOnlyOneAutoLoginSelected;			
		}
		
		
		private string FormatOptionalString (string s)
		{
			if (null == s) 
			{
				return "-none-";
			}
			else
			{
				return s;
			}
		}
		
		
		private void ShowOrHideFrames()
		{
			bool isRemoteFile = optTelnet.Checked  ||  optSSH.Checked;
			bool isSSH = optSSH.Checked;
			
			if (isRemoteFile)
			{
				grpTelnet.Text = optSSH.Checked ? "SSH settings" : "Telnet settings";
					
				this.txtUsername.Visible = isSSH;
				this.lblUsername.Visible = isSSH;
				this.lblAuthMechanism.Visible = isSSH;
				this.cboAuthMechanism.Visible = isSSH;
				this.lblUsernameAndPassword.Visible = ! isSSH;
				this.lblSshPassword.Visible = isSSH  &&  2 == cboAuthMechanism.SelectedIndex;
				this.txtSshPassword.Visible = isSSH  &&  2 == cboAuthMechanism.SelectedIndex;
			}
			
			grpLocal.Visible = ! isRemoteFile;
			grpTelnet.Visible = isRemoteFile;
		}
		
		
		
		private bool DoSave()
		{
			string sPath = optLocal.Checked ? txtLocalPath.Text : txtTelnetPath.Text;
			
			if (0 == sPath.Length)
			{
				MessageBox.Show ("You must enter a path for the file.", this.Text);
				return false;
			}
			
			
			// Make sure the logfile has a name			
			if (0 == txtDisplayName.Text.Length)
			{
				txtDisplayName.Text = GetFileNameFromPath(sPath);					
			}
			
			// Check for remote host if necessary
			if ((optTelnet.Checked  ||  optSSH.Checked)  &&  0 == txtHost.Text.Length)
			{
				MessageBox.Show ("You must enter a remote host for a telnet or SSH file.", this.Text);
				return false;
			}
			
			int iPort = 0;
			
			// Check for remote host if necessary
			if ((optTelnet.Checked  ||  optSSH.Checked)  &&  0 != txtPort.Text.Length)
			{				
				bool isNumeric = Int32.TryParse(txtPort.Text, out iPort);
				
				if (! (isNumeric  &&  iPort > 0  &&  iPort < 65536))
				{	
					MessageBox.Show ("You must enter a valid remote port for a telnet or SSH file, or leave the field blank to use the default.", this.Text);
					return false;
				}
			}
			
			// Check for remote command if necessary
			if ((optTelnet.Checked  ||  optSSH.Checked)  &&  0 == txtTailCommand.Text.Length)
			{
				MessageBox.Show ("You must enter a tail command for a telnet or SSH file.", this.Text);
				return false;
			}
			
			// Check for SSH username
			if (optSSH.Checked  &&  0 == txtUsername.Text.Length)
			{
				MessageBox.Show ("You must enter username for an SSH file.", this.Text);
				return false;
			}
			
			if (chkRegex.Checked  &&  ! IsRegexValid(txtRegex.Text))
			{
				MessageBox.Show ("The 'file' regular expression is not a valid", this.Text);
				return false;
			}
			
			
			// Copy the values across to the working version
			original_i.name = txtDisplayName.Text;
			original_i.path = sPath;
			original_i.match = working_i.match;
			
			if (chkRegex.Checked)
			{
				original_i.localPathRegex = txtRegex.Text;
			}
			else
			{
				original_i.localPathRegex = "";
			}
			
			
			if (radMultipleMatchesChooseFirst.Checked)
			{
				original_i.multipleFileMatchStrategy = multipleFileMatchStrategyType.chooseFirst;
			}
			else if (radMultipleMatchesChooseLast.Checked)
			{
				original_i.multipleFileMatchStrategy = multipleFileMatchStrategyType.chooseLast;
			}
			else
			{
				original_i.multipleFileMatchStrategy = multipleFileMatchStrategyType.chooseMostRecent;
			}
			
			if (optSSH.Checked)
			{
				original_i.telnetProtocol = protocolType.ssh;
				original_i.sshUsername = txtUsername.Text;
				original_i.telnetHost = txtHost.Text;				
				original_i.telnetPort = iPort;
				original_i.telnetCommand = txtTailCommand.Text;								
				original_i.autoLogin = working_i.autoLogin;
				original_i.sshEncryptedPassword = "";
								
				switch (cboAuthMechanism.SelectedIndex)
				{
					case 0:
						original_i.sshAuthMechanism = sshAuthMechanismType.promptForPassword;
						break;
						
					case 1:
						original_i.sshAuthMechanism = sshAuthMechanismType.publicKey;
						break;
						
					case 2:
						original_i.sshAuthMechanism = sshAuthMechanismType.storePasswordInsecure;
						original_i.sshEncryptedPassword = PasswordHelper.Encrypt(txtSshPassword.Text);
						break;
						
					default:
						throw new Exception("Unexpected 'selected index' value for auth type combo: " + cboAuthMechanism.SelectedIndex);
				}
				
			}
			else if (optTelnet.Checked)
			{
				original_i.telnetProtocol = protocolType.telnet;
				original_i.sshUsername = null;
				original_i.telnetHost = txtHost.Text;
				original_i.telnetPort = iPort;
				original_i.telnetCommand = txtTailCommand.Text;				
				original_i.autoLogin = working_i.autoLogin;
			}
			else
			{
				original_i.sshUsername = null;
				original_i.telnetHost = null;
				original_i.telnetPort = 0;
				original_i.telnetCommand = null;
				original_i.autoLogin = new logsetLogfileAutoLogin[0];
			}
			
			return true;
		}
		
		
		private string GetFileNameFromPath (string sPath_p)
		{
			if (sPath_p.IndexOf("/") >= 0)
			{
				string[] vParts = sPath_p.Split('/');
				return vParts[vParts.Length-1];
			}
			else if (sPath_p.IndexOf("\\") >= 0)
			{
				string[] vParts = sPath_p.Split('\\');
				return vParts[vParts.Length-1];
			}
			else
			{
				return sPath_p;
			}
		}
		
		
		void OptLocalCheckedChanged(object sender, System.EventArgs e)
		{
			ShowOrHideFrames();
		}
		
		void OptTelnetCheckedChanged(object sender, System.EventArgs e)
		{
			ShowOrHideFrames();
		}
		
		void OptSSHCheckedChanged(object sender, System.EventArgs e)
		{
			ShowOrHideFrames();
		}
		
		void CmdOKClick(object sender, System.EventArgs e)
		{
			if (DoSave())
			{
				bWasCancelled_i = false;
				this.Close();
			}
		}
		
		void CmdCancelClick(object sender, System.EventArgs e)
		{
			bWasCancelled_i = true;
			this.Close();
		}
		
		
		
		
		void GrpTelnetEnter(object sender, System.EventArgs e)
		{
			
		}
		
		void CmdNewMatchClick(object sender, System.EventArgs e)
		{
			logsetLogfileMatch match = new logsetLogfileMatch();
			
			MatchForm f = new MatchForm(match);
			f.ShowDialog();
			
			if (! f.WasCancelled)
			{
				logsetLogfileMatch[] origArray = working_i.match;
				
				logsetLogfileMatch[] newArray = new logsetLogfileMatch[origArray.Length+1];
				
				for (int i=0; i<origArray.Length; i++)
				{
					newArray[i] = origArray[i];
				}
				     
				newArray[newArray.Length-1] = match;
				
				working_i.match = newArray;
			}
			
			PopulateMatchesList();
		}
		
		void CmdEditMatchClick(object sender, System.EventArgs e)
		{
			if (0 == lvwMatches.Items.Count  ||  0 == lvwMatches.SelectedIndices.Count) return;
			
			int iIndex = lvwMatches.SelectedIndices[0];
			logsetLogfileMatch match = working_i.match[iIndex];			
			
			MatchForm f = new MatchForm(match);
			f.ShowDialog();
			
			PopulateMatchesList();
		}
		
		
		
		void LvwMatchesDoubleClick(object sender, System.EventArgs e)
		{
			CmdEditMatchClick(sender, e);
		}
		
		
		
		void CmdDeleteMatchClick(object sender, System.EventArgs e)
		{
			if (0 == lvwMatches.Items.Count  ||  0 == lvwMatches.SelectedIndices.Count) return;
			
			string sConfirmationMessage = (lvwMatches.SelectedItems.Count > 1 ? 
			                               "Are you sure you want to remove these searches?\n" :
			                               "Are you sure you want to remove this search?\n");
			
			IList matchesToDelete = new ArrayList();
			
			foreach (ListViewItem item in lvwMatches.SelectedItems)
			{
				logsetLogfileMatch match = working_i.match[item.Index];
				matchesToDelete.Add(item.Index);					
				sConfirmationMessage += "\n    " + match.pattern.Value;
			}
			
			if (DialogResult.Yes == MessageBox.Show (sConfirmationMessage, this.Text, MessageBoxButtons.YesNo))
			{				
				logsetLogfileMatch[] origArray = working_i.match;					
				logsetLogfileMatch[] newArray = new logsetLogfileMatch[origArray.Length-matchesToDelete.Count];

				int iOrigArrayIndex = 0;
				int iNewArrayIndex = 0;
				
				for (iOrigArrayIndex=0; iOrigArrayIndex < origArray.Length; iOrigArrayIndex++)
				{					
					if (! matchesToDelete.Contains(iOrigArrayIndex))
					{
						newArray[iNewArrayIndex] = origArray[iOrigArrayIndex];
						iNewArrayIndex++;						
					}
				}
								
				working_i.match = newArray;
				
				PopulateMatchesList();
			}
		}
		
		void CmdMatchUpClick(object sender, System.EventArgs e)
		{
			if (lvwMatches.Items.Count < 2  ||  
			    0 == lvwMatches.SelectedIndices.Count) return;
			
			int iIndex = lvwMatches.SelectedIndices[0];
			if (0 == iIndex) return;
			
			// Swap the matches around
			logsetLogfileMatch tmp = working_i.match[iIndex-1];			
			working_i.match[iIndex-1] = working_i.match[iIndex];
			working_i.match[iIndex] = tmp;
			
			PopulateMatchesList();
			
			lvwMatches.Items[iIndex-1].Selected = true;					
		}
		
		void CmdMatchDownClick(object sender, System.EventArgs e)
		{
			if (lvwMatches.Items.Count < 2  ||  0 == lvwMatches.SelectedIndices.Count) return;
			
			int iIndex = lvwMatches.SelectedIndices[0];
			if (lvwMatches.Items.Count-1 == iIndex) return;
			
			// Swap the matches around
			logsetLogfileMatch tmp = working_i.match[iIndex+1];
			working_i.match[iIndex+1] = working_i.match[iIndex];
			working_i.match[iIndex] = tmp;
			
			PopulateMatchesList();
			
			lvwMatches.Items[iIndex+1].Selected = true;	
		}
		
		
		
		
		
		
		void CmdAutoLoginUpClick(object sender, System.EventArgs e)
		{
			if (lvwAutoLogins.Items.Count < 2  ||  
			    0 == lvwAutoLogins.SelectedIndices.Count) return;
			
			int iIndex = lvwAutoLogins.SelectedIndices[0];
			if (0 == iIndex) return;
			
			// Swap the matches around
			logsetLogfileAutoLogin tmp = working_i.autoLogin[iIndex-1];			
			working_i.autoLogin[iIndex-1] = working_i.autoLogin[iIndex];
			working_i.autoLogin[iIndex] = tmp;
			
			PopulateAutoLoginList();
			
			lvwAutoLogins.Items[iIndex-1].Selected = true;	
		}
		
		void CmdAutoLoginDownClick(object sender, System.EventArgs e)
		{
			if (lvwAutoLogins.Items.Count < 2  ||  0 == lvwAutoLogins.SelectedIndices.Count) return;
			
			int iIndex = lvwAutoLogins.SelectedIndices[0];
			if (lvwAutoLogins.Items.Count-1 == iIndex) return;
			
			// Swap the matches around
			logsetLogfileAutoLogin tmp = working_i.autoLogin[iIndex+1];
			working_i.autoLogin[iIndex+1] = working_i.autoLogin[iIndex];
			working_i.autoLogin[iIndex] = tmp;
			
			PopulateAutoLoginList();
			
			lvwAutoLogins.Items[iIndex+1].Selected = true;	
		}
		
		void CmdAutoLoginNewClick(object sender, System.EventArgs e)
		{
			logsetLogfileAutoLogin autologin = new logsetLogfileAutoLogin();
			autologin.send = new logsetLogfileAutoLoginSend();
			
			AutoLoginForm f = new AutoLoginForm(autologin);
			f.ShowDialog();
			
			if (! f.WasCancelled)
			{
				logsetLogfileAutoLogin[] origArray = working_i.autoLogin;
				
				logsetLogfileAutoLogin[] newArray = new logsetLogfileAutoLogin[origArray.Length+1];
				
				for (int i=0; i<origArray.Length; i++)
				{
					newArray[i] = origArray[i];
				}
				     
				newArray[newArray.Length-1] = autologin;
				
				working_i.autoLogin = newArray;
			}
			
			PopulateAutoLoginList();
		}
		
		void CmdAutoLoginEditClick(object sender, System.EventArgs e)
		{
			if (0 == lvwAutoLogins.Items.Count  ||  0 == lvwAutoLogins.SelectedIndices.Count) return;
			
			int iIndex = lvwAutoLogins.SelectedIndices[0];
			logsetLogfileAutoLogin autologin = working_i.autoLogin[iIndex];			
			
			AutoLoginForm f = new AutoLoginForm(autologin);
			f.ShowDialog();
			
			PopulateAutoLoginList();
		}
		
		
		void LvwAutoLoginsDoubleClick(object sender, System.EventArgs e)
		{
			CmdAutoLoginEditClick(sender, e);
		}
		
		
		void CmdAutoLoginDeleteClick(object sender, System.EventArgs e)
		{
			if (0 == lvwAutoLogins.Items.Count  ||  0 == lvwAutoLogins.SelectedIndices.Count) return;
			
			string sConfirmationMessage = (lvwAutoLogins.SelectedItems.Count > 1 ? 
			                               "Are you sure you want to remove these auto-login checks?\n" :
			                               "Are you sure you want to remove this auto-login check?\n");
			
			IList autologinsToDelete = new ArrayList();
			
			foreach (ListViewItem item in lvwAutoLogins.SelectedItems)
			{
				logsetLogfileAutoLogin autologin = working_i.autoLogin[item.Index];
				autologinsToDelete.Add(item.Index);					
			}
			
			if (DialogResult.Yes == MessageBox.Show (sConfirmationMessage, this.Text, MessageBoxButtons.YesNo))
			{				
				logsetLogfileAutoLogin[] origArray = working_i.autoLogin;					
				logsetLogfileAutoLogin[] newArray = new logsetLogfileAutoLogin[origArray.Length-autologinsToDelete.Count];

				int iOrigArrayIndex = 0;
				int iNewArrayIndex = 0;
				
				for (iOrigArrayIndex=0; iOrigArrayIndex < origArray.Length; iOrigArrayIndex++)
				{					
					if (!autologinsToDelete.Contains(iOrigArrayIndex))
					{
						newArray[iNewArrayIndex] = origArray[iOrigArrayIndex];
						iNewArrayIndex++;
					}
				}				
								
				working_i.autoLogin = newArray;
				
				PopulateAutoLoginList();
			}
		}
		
		
		
		void CmdLocalBrowseClick(object sender, System.EventArgs e)
		{
			if (System.IO.File.Exists(txtLocalPath.Text))
			{
				openFileDialog1.FileName = txtLocalPath.Text;
			}
			
			openFileDialog1.Multiselect = false;
			if (DialogResult.OK == openFileDialog1.ShowDialog())
			{
				txtLocalPath.Text = openFileDialog1.FileName;
			}						
		}
		
		
		
		
		
		
		
		
		string JoinStringArray (ArrayList strings_p, string sConjunction_p)
		{
			return String.Join(sConjunction_p, (string[])strings_p.ToArray(typeof(string)));
		}
		
		
		
		bool IsRegexValid(string sRegex_p)
		{
			try
			{
				Regex regex = new Regex(sRegex_p);				
				return true;
			}
			catch (Exception e)
			{
				return false;
			}
		}
		
		
		
		
		
		#region Windows Forms Designer generated code
		/// <summary>
		/// This method is required for Windows Forms designer support.
		/// Do not change the method contents inside the source code editor. The Forms designer might
		/// not be able to load this method if it was changed manually.
		/// </summary>
		private void InitializeComponent() {
			this.components = new System.ComponentModel.Container();
			this.cmdMatchDown = new System.Windows.Forms.Button();
			this.grpTelnet = new System.Windows.Forms.GroupBox();
			this.cboAuthMechanism = new System.Windows.Forms.ComboBox();
			this.groupBox2 = new System.Windows.Forms.GroupBox();
			this.cmdAutoLoginDelete = new System.Windows.Forms.Button();
			this.lvwAutoLogins = new System.Windows.Forms.ListView();
			this.colWaitFor = new System.Windows.Forms.ColumnHeader();
			this.colSend = new System.Windows.Forms.ColumnHeader();
			this.imageList1 = new System.Windows.Forms.ImageList(this.components);
			this.cmdAutoLoginEdit = new System.Windows.Forms.Button();
			this.cmdAutoLoginNew = new System.Windows.Forms.Button();
			this.cmdAutoLoginDown = new System.Windows.Forms.Button();
			this.cmdAutoLoginUp = new System.Windows.Forms.Button();
			this.txtTelnetPath = new System.Windows.Forms.TextBox();
			this.label3 = new System.Windows.Forms.Label();
			this.txtPort = new System.Windows.Forms.TextBox();
			this.label8 = new System.Windows.Forms.Label();
			this.txtHost = new System.Windows.Forms.TextBox();
			this.label4 = new System.Windows.Forms.Label();
			this.txtTailCommand = new System.Windows.Forms.TextBox();
			this.label5 = new System.Windows.Forms.Label();
			this.lblSshPassword = new System.Windows.Forms.Label();
			this.lblAuthMechanism = new System.Windows.Forms.Label();
			this.lblUsername = new System.Windows.Forms.Label();
			this.txtSshPassword = new System.Windows.Forms.TextBox();
			this.txtUsername = new System.Windows.Forms.TextBox();
			this.lblUsernameAndPassword = new System.Windows.Forms.Label();
			this.cmdLocalBrowse = new System.Windows.Forms.Button();
			this.cmdImport = new System.Windows.Forms.Button();
			this.colMatch = new System.Windows.Forms.ColumnHeader();
			this.txtDisplayName = new System.Windows.Forms.TextBox();
			this.grpLocal = new System.Windows.Forms.GroupBox();
			this.txtRegex = new System.Windows.Forms.TextBox();
			this.label7 = new System.Windows.Forms.Label();
			this.radMultipleMatchesChooseMostRecent = new System.Windows.Forms.RadioButton();
			this.radMultipleMatchesChooseLast = new System.Windows.Forms.RadioButton();
			this.radMultipleMatchesChooseFirst = new System.Windows.Forms.RadioButton();
			this.chkRegex = new System.Windows.Forms.CheckBox();
			this.txtLocalPath = new System.Windows.Forms.TextBox();
			this.label2 = new System.Windows.Forms.Label();
			this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog();
			this.cmdEditMatch = new System.Windows.Forms.Button();
			this.cmdDeleteMatch = new System.Windows.Forms.Button();
			this.lvwMatches = new System.Windows.Forms.ListView();
			this.colActions = new System.Windows.Forms.ColumnHeader();
			this.label1 = new System.Windows.Forms.Label();
			this.cmdCancel = new System.Windows.Forms.Button();
			this.optSSH = new System.Windows.Forms.RadioButton();
			this.optLocal = new System.Windows.Forms.RadioButton();
			this.cmdMatchUp = new System.Windows.Forms.Button();
			this.groupBox1 = new System.Windows.Forms.GroupBox();
			this.cmdNewMatch = new System.Windows.Forms.Button();
			this.optTelnet = new System.Windows.Forms.RadioButton();
			this.cmdOK = new System.Windows.Forms.Button();
			this.label6 = new System.Windows.Forms.Label();
			this.groupBox3 = new System.Windows.Forms.GroupBox();
			this.grpTelnet.SuspendLayout();
			this.groupBox2.SuspendLayout();
			this.grpLocal.SuspendLayout();
			this.groupBox1.SuspendLayout();
			this.groupBox3.SuspendLayout();
			this.SuspendLayout();
			// 
			// cmdMatchDown
			// 
			this.cmdMatchDown.Location = new System.Drawing.Point(72, 128);
			this.cmdMatchDown.Name = "cmdMatchDown";
			this.cmdMatchDown.Size = new System.Drawing.Size(48, 23);
			this.cmdMatchDown.TabIndex = 1;
			this.cmdMatchDown.Tag = "Moves the selected replacement/highlight operation down in the list.";
			this.cmdMatchDown.Text = "Down";
			this.cmdMatchDown.Click += new System.EventHandler(this.CmdMatchDownClick);
			// 
			// grpTelnet
			// 
			this.grpTelnet.Controls.Add(this.cboAuthMechanism);
			this.grpTelnet.Controls.Add(this.groupBox2);
			this.grpTelnet.Controls.Add(this.txtTelnetPath);
			this.grpTelnet.Controls.Add(this.label3);
			this.grpTelnet.Controls.Add(this.txtPort);
			this.grpTelnet.Controls.Add(this.label8);
			this.grpTelnet.Controls.Add(this.txtHost);
			this.grpTelnet.Controls.Add(this.label4);
			this.grpTelnet.Controls.Add(this.txtTailCommand);
			this.grpTelnet.Controls.Add(this.label5);
			this.grpTelnet.Controls.Add(this.lblSshPassword);
			this.grpTelnet.Controls.Add(this.lblAuthMechanism);
			this.grpTelnet.Controls.Add(this.lblUsername);
			this.grpTelnet.Controls.Add(this.txtSshPassword);
			this.grpTelnet.Controls.Add(this.txtUsername);
			this.grpTelnet.Controls.Add(this.lblUsernameAndPassword);
			this.grpTelnet.Location = new System.Drawing.Point(16, 88);
			this.grpTelnet.Name = "grpTelnet";
			this.grpTelnet.Size = new System.Drawing.Size(472, 412);
			this.grpTelnet.TabIndex = 3;
			this.grpTelnet.TabStop = false;
			this.grpTelnet.Text = "Telnet file details";
			this.grpTelnet.Enter += new System.EventHandler(this.GrpTelnetEnter);
			// 
			// cboAuthMechanism
			// 
			this.cboAuthMechanism.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
			this.cboAuthMechanism.FormattingEnabled = true;
			this.cboAuthMechanism.Items.AddRange(new object[] {
									"Prompt for the password on startup",
									"Use public key authentication",
									"Store the password (NOT SECURE!)"});
			this.cboAuthMechanism.Location = new System.Drawing.Point(104, 160);
			this.cboAuthMechanism.Name = "cboAuthMechanism";
			this.cboAuthMechanism.Size = new System.Drawing.Size(352, 21);
			this.cboAuthMechanism.TabIndex = 5;
			this.cboAuthMechanism.SelectedIndexChanged += new System.EventHandler(this.CboAuthMechanismSelectedIndexChanged);
			// 
			// groupBox2
			// 
			this.groupBox2.Controls.Add(this.cmdAutoLoginDelete);
			this.groupBox2.Controls.Add(this.lvwAutoLogins);
			this.groupBox2.Controls.Add(this.cmdAutoLoginEdit);
			this.groupBox2.Controls.Add(this.cmdAutoLoginNew);
			this.groupBox2.Controls.Add(this.cmdAutoLoginDown);
			this.groupBox2.Controls.Add(this.cmdAutoLoginUp);
			this.groupBox2.Location = new System.Drawing.Point(16, 226);
			this.groupBox2.Name = "groupBox2";
			this.groupBox2.Size = new System.Drawing.Size(440, 168);
			this.groupBox2.TabIndex = 3;
			this.groupBox2.TabStop = false;
			this.groupBox2.Text = "Auto login commands";
			// 
			// cmdAutoLoginDelete
			// 
			this.cmdAutoLoginDelete.Location = new System.Drawing.Point(352, 128);
			this.cmdAutoLoginDelete.Name = "cmdAutoLoginDelete";
			this.cmdAutoLoginDelete.Size = new System.Drawing.Size(75, 23);
			this.cmdAutoLoginDelete.TabIndex = 1;
			this.cmdAutoLoginDelete.Tag = "Deletes the currently selected \'auto login\' details.";
			this.cmdAutoLoginDelete.Text = "Delete...";
			this.cmdAutoLoginDelete.Click += new System.EventHandler(this.CmdAutoLoginDeleteClick);
			// 
			// lvwAutoLogins
			// 
			this.lvwAutoLogins.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
									this.colWaitFor,
									this.colSend});
			this.lvwAutoLogins.FullRowSelect = true;
			this.lvwAutoLogins.HideSelection = false;
			this.lvwAutoLogins.Location = new System.Drawing.Point(16, 24);
			this.lvwAutoLogins.Name = "lvwAutoLogins";
			this.lvwAutoLogins.Size = new System.Drawing.Size(408, 96);
			this.lvwAutoLogins.SmallImageList = this.imageList1;
			this.lvwAutoLogins.TabIndex = 0;
			this.lvwAutoLogins.Tag = "Auto login allows you to wait for certain prompts to be echoed to the screen (e.g" +
			". \'login\' and \'password\') and to send a given response when these prompts are de" +
			"tected.";
			this.lvwAutoLogins.UseCompatibleStateImageBehavior = false;
			this.lvwAutoLogins.View = System.Windows.Forms.View.Details;
			this.lvwAutoLogins.SelectedIndexChanged += new System.EventHandler(this.LvwAutoLoginsSelectedIndexChanged);
			this.lvwAutoLogins.DoubleClick += new System.EventHandler(this.LvwAutoLoginsDoubleClick);
			// 
			// colWaitFor
			// 
			this.colWaitFor.Text = "Wait for this";
			this.colWaitFor.Width = 200;
			// 
			// colSend
			// 
			this.colSend.Text = "Then send this text";
			this.colSend.Width = 200;
			// 
			// imageList1
			// 
			this.imageList1.ColorDepth = System.Windows.Forms.ColorDepth.Depth8Bit;
			this.imageList1.ImageSize = new System.Drawing.Size(16, 16);
			this.imageList1.TransparentColor = System.Drawing.Color.Transparent;
			// 
			// cmdAutoLoginEdit
			// 
			this.cmdAutoLoginEdit.Location = new System.Drawing.Point(272, 128);
			this.cmdAutoLoginEdit.Name = "cmdAutoLoginEdit";
			this.cmdAutoLoginEdit.Size = new System.Drawing.Size(75, 23);
			this.cmdAutoLoginEdit.TabIndex = 1;
			this.cmdAutoLoginEdit.Tag = "Allows you to view and edit the currently selected \'auto login\' setting.";
			this.cmdAutoLoginEdit.Text = "Edit...";
			this.cmdAutoLoginEdit.Click += new System.EventHandler(this.CmdAutoLoginEditClick);
			// 
			// cmdAutoLoginNew
			// 
			this.cmdAutoLoginNew.Location = new System.Drawing.Point(192, 128);
			this.cmdAutoLoginNew.Name = "cmdAutoLoginNew";
			this.cmdAutoLoginNew.Size = new System.Drawing.Size(75, 23);
			this.cmdAutoLoginNew.TabIndex = 1;
			this.cmdAutoLoginNew.Tag = "Allows you to create a new auto login setting for this connection.";
			this.cmdAutoLoginNew.Text = "New...";
			this.cmdAutoLoginNew.Click += new System.EventHandler(this.CmdAutoLoginNewClick);
			// 
			// cmdAutoLoginDown
			// 
			this.cmdAutoLoginDown.Location = new System.Drawing.Point(72, 128);
			this.cmdAutoLoginDown.Name = "cmdAutoLoginDown";
			this.cmdAutoLoginDown.Size = new System.Drawing.Size(48, 23);
			this.cmdAutoLoginDown.TabIndex = 1;
			this.cmdAutoLoginDown.Tag = "Moves the currently selected \'auto login\' item downwards in the list.";
			this.cmdAutoLoginDown.Text = "Down";
			this.cmdAutoLoginDown.Click += new System.EventHandler(this.CmdAutoLoginDownClick);
			// 
			// cmdAutoLoginUp
			// 
			this.cmdAutoLoginUp.Location = new System.Drawing.Point(16, 128);
			this.cmdAutoLoginUp.Name = "cmdAutoLoginUp";
			this.cmdAutoLoginUp.Size = new System.Drawing.Size(48, 23);
			this.cmdAutoLoginUp.TabIndex = 1;
			this.cmdAutoLoginUp.Tag = "Moves the currently selected \'auto login\' item upwards in the list.";
			this.cmdAutoLoginUp.Text = "Up";
			this.cmdAutoLoginUp.Click += new System.EventHandler(this.CmdAutoLoginUpClick);
			// 
			// txtTelnetPath
			// 
			this.txtTelnetPath.Location = new System.Drawing.Point(104, 32);
			this.txtTelnetPath.Name = "txtTelnetPath";
			this.txtTelnetPath.Size = new System.Drawing.Size(352, 20);
			this.txtTelnetPath.TabIndex = 1;
			// 
			// label3
			// 
			this.label3.Location = new System.Drawing.Point(16, 32);
			this.label3.Name = "label3";
			this.label3.Size = new System.Drawing.Size(104, 24);
			this.label3.TabIndex = 0;
			this.label3.Text = "Path to file on remote machine:";
			// 
			// txtPort
			// 
			this.txtPort.Location = new System.Drawing.Point(358, 98);
			this.txtPort.Name = "txtPort";
			this.txtPort.Size = new System.Drawing.Size(98, 20);
			this.txtPort.TabIndex = 1;
			this.txtPort.Tag = "Enter the host name or IP address of the telnet host which contains the log files" +
			".";
			// 
			// label8
			// 
			this.label8.Location = new System.Drawing.Point(267, 98);
			this.label8.Name = "label8";
			this.label8.Size = new System.Drawing.Size(91, 20);
			this.label8.TabIndex = 0;
			this.label8.Text = "Port (optional):";
			// 
			// txtHost
			// 
			this.txtHost.Location = new System.Drawing.Point(104, 98);
			this.txtHost.Name = "txtHost";
			this.txtHost.Size = new System.Drawing.Size(128, 20);
			this.txtHost.TabIndex = 1;
			this.txtHost.Tag = "Enter the host name or IP address of the telnet host which contains the log files" +
			".";
			// 
			// label4
			// 
			this.label4.Location = new System.Drawing.Point(16, 98);
			this.label4.Name = "label4";
			this.label4.Size = new System.Drawing.Size(168, 16);
			this.label4.TabIndex = 0;
			this.label4.Text = "Host name:";
			// 
			// txtTailCommand
			// 
			this.txtTailCommand.Location = new System.Drawing.Point(104, 65);
			this.txtTailCommand.Name = "txtTailCommand";
			this.txtTailCommand.Size = new System.Drawing.Size(352, 20);
			this.txtTailCommand.TabIndex = 1;
			this.txtTailCommand.Tag = "This is the command to run in order to \'tail\' the log file.  The path to the log " +
			"file will be appended to this command when it is run.";
			// 
			// label5
			// 
			this.label5.Location = new System.Drawing.Point(16, 65);
			this.label5.Name = "label5";
			this.label5.Size = new System.Drawing.Size(80, 16);
			this.label5.TabIndex = 0;
			this.label5.Text = "Tail command:";
			// 
			// lblSshPassword
			// 
			this.lblSshPassword.Location = new System.Drawing.Point(16, 196);
			this.lblSshPassword.Name = "lblSshPassword";
			this.lblSshPassword.Size = new System.Drawing.Size(82, 27);
			this.lblSshPassword.TabIndex = 0;
			this.lblSshPassword.Text = "Password:";
			// 
			// lblAuthMechanism
			// 
			this.lblAuthMechanism.Location = new System.Drawing.Point(16, 165);
			this.lblAuthMechanism.Name = "lblAuthMechanism";
			this.lblAuthMechanism.Size = new System.Drawing.Size(90, 27);
			this.lblAuthMechanism.TabIndex = 0;
			this.lblAuthMechanism.Text = "Authentication:";
			// 
			// lblUsername
			// 
			this.lblUsername.Location = new System.Drawing.Point(16, 133);
			this.lblUsername.Name = "lblUsername";
			this.lblUsername.Size = new System.Drawing.Size(64, 16);
			this.lblUsername.TabIndex = 0;
			this.lblUsername.Text = "Username:";
			// 
			// txtSshPassword
			// 
			this.txtSshPassword.Location = new System.Drawing.Point(104, 193);
			this.txtSshPassword.Name = "txtSshPassword";
			this.txtSshPassword.PasswordChar = '*';
			this.txtSshPassword.Size = new System.Drawing.Size(128, 20);
			this.txtSshPassword.TabIndex = 1;
			this.txtSshPassword.Tag = "";
			// 
			// txtUsername
			// 
			this.txtUsername.Location = new System.Drawing.Point(104, 133);
			this.txtUsername.Name = "txtUsername";
			this.txtUsername.Size = new System.Drawing.Size(128, 20);
			this.txtUsername.TabIndex = 1;
			this.txtUsername.Tag = "For SSH logins you can specify the username here.  You will be prompted for the p" +
			"assword on startup.";
			// 
			// lblUsernameAndPassword
			// 
			this.lblUsernameAndPassword.Location = new System.Drawing.Point(16, 133);
			this.lblUsernameAndPassword.Name = "lblUsernameAndPassword";
			this.lblUsernameAndPassword.Size = new System.Drawing.Size(432, 32);
			this.lblUsernameAndPassword.TabIndex = 0;
			this.lblUsernameAndPassword.Text = "Use the Auto Login feature below to automatically send username and password.";
			// 
			// cmdLocalBrowse
			// 
			this.cmdLocalBrowse.Location = new System.Drawing.Point(384, 40);
			this.cmdLocalBrowse.Name = "cmdLocalBrowse";
			this.cmdLocalBrowse.Size = new System.Drawing.Size(75, 23);
			this.cmdLocalBrowse.TabIndex = 2;
			this.cmdLocalBrowse.Tag = "Clicking this button will allow you to use the standard Windows \'open file\' box t" +
			"o locate your log file.";
			this.cmdLocalBrowse.Text = "Browse...";
			this.cmdLocalBrowse.Click += new System.EventHandler(this.CmdLocalBrowseClick);
			// 
			// cmdImport
			// 
			this.cmdImport.Location = new System.Drawing.Point(520, 120);
			this.cmdImport.Name = "cmdImport";
			this.cmdImport.Size = new System.Drawing.Size(104, 23);
			this.cmdImport.TabIndex = 8;
			this.cmdImport.Text = "Import Settings...";
			this.cmdImport.Click += new System.EventHandler(this.CmdImportClick);
			// 
			// colMatch
			// 
			this.colMatch.Text = "Look for";
			this.colMatch.Width = 120;
			// 
			// txtDisplayName
			// 
			this.txtDisplayName.Location = new System.Drawing.Point(112, 24);
			this.txtDisplayName.Name = "txtDisplayName";
			this.txtDisplayName.Size = new System.Drawing.Size(256, 20);
			this.txtDisplayName.TabIndex = 1;
			this.txtDisplayName.Tag = "An arbitrary name for this log file, e.g. \"JBoss server log\"";
			// 
			// grpLocal
			// 
			this.grpLocal.Controls.Add(this.txtRegex);
			this.grpLocal.Controls.Add(this.label7);
			this.grpLocal.Controls.Add(this.radMultipleMatchesChooseMostRecent);
			this.grpLocal.Controls.Add(this.radMultipleMatchesChooseLast);
			this.grpLocal.Controls.Add(this.radMultipleMatchesChooseFirst);
			this.grpLocal.Controls.Add(this.chkRegex);
			this.grpLocal.Controls.Add(this.cmdLocalBrowse);
			this.grpLocal.Controls.Add(this.txtLocalPath);
			this.grpLocal.Controls.Add(this.label2);
			this.grpLocal.Location = new System.Drawing.Point(16, 88);
			this.grpLocal.Name = "grpLocal";
			this.grpLocal.Size = new System.Drawing.Size(472, 412);
			this.grpLocal.TabIndex = 4;
			this.grpLocal.TabStop = false;
			this.grpLocal.Text = "Local Windows file details";
			// 
			// txtRegex
			// 
			this.txtRegex.Location = new System.Drawing.Point(272, 75);
			this.txtRegex.Name = "txtRegex";
			this.txtRegex.Size = new System.Drawing.Size(187, 20);
			this.txtRegex.TabIndex = 1;
			// 
			// label7
			// 
			this.label7.Location = new System.Drawing.Point(16, 108);
			this.label7.Name = "label7";
			this.label7.Size = new System.Drawing.Size(230, 23);
			this.label7.TabIndex = 5;
			this.label7.Text = "If multiple files are found then...";
			// 
			// radMultipleMatchesChooseMostRecent
			// 
			this.radMultipleMatchesChooseMostRecent.Location = new System.Drawing.Point(80, 182);
			this.radMultipleMatchesChooseMostRecent.Name = "radMultipleMatchesChooseMostRecent";
			this.radMultipleMatchesChooseMostRecent.Size = new System.Drawing.Size(304, 24);
			this.radMultipleMatchesChooseMostRecent.TabIndex = 4;
			this.radMultipleMatchesChooseMostRecent.TabStop = true;
			this.radMultipleMatchesChooseMostRecent.Text = "Choose the most recent file";
			this.radMultipleMatchesChooseMostRecent.UseVisualStyleBackColor = true;
			// 
			// radMultipleMatchesChooseLast
			// 
			this.radMultipleMatchesChooseLast.Location = new System.Drawing.Point(80, 158);
			this.radMultipleMatchesChooseLast.Name = "radMultipleMatchesChooseLast";
			this.radMultipleMatchesChooseLast.Size = new System.Drawing.Size(248, 24);
			this.radMultipleMatchesChooseLast.TabIndex = 4;
			this.radMultipleMatchesChooseLast.TabStop = true;
			this.radMultipleMatchesChooseLast.Text = "Choose last file";
			this.radMultipleMatchesChooseLast.UseVisualStyleBackColor = true;
			// 
			// radMultipleMatchesChooseFirst
			// 
			this.radMultipleMatchesChooseFirst.Location = new System.Drawing.Point(80, 133);
			this.radMultipleMatchesChooseFirst.Name = "radMultipleMatchesChooseFirst";
			this.radMultipleMatchesChooseFirst.Size = new System.Drawing.Size(272, 24);
			this.radMultipleMatchesChooseFirst.TabIndex = 4;
			this.radMultipleMatchesChooseFirst.TabStop = true;
			this.radMultipleMatchesChooseFirst.Text = "Choose the first file";
			this.radMultipleMatchesChooseFirst.UseVisualStyleBackColor = true;
			// 
			// chkRegex
			// 
			this.chkRegex.Location = new System.Drawing.Point(16, 73);
			this.chkRegex.Name = "chkRegex";
			this.chkRegex.Size = new System.Drawing.Size(267, 24);
			this.chkRegex.TabIndex = 3;
			this.chkRegex.Text = "File path should match this regular expression:";
			this.chkRegex.UseVisualStyleBackColor = true;
			this.chkRegex.CheckedChanged += new System.EventHandler(this.ChkRegexCheckedChanged);
			// 
			// txtLocalPath
			// 
			this.txtLocalPath.Location = new System.Drawing.Point(80, 40);
			this.txtLocalPath.Name = "txtLocalPath";
			this.txtLocalPath.Size = new System.Drawing.Size(304, 20);
			this.txtLocalPath.TabIndex = 1;
			// 
			// label2
			// 
			this.label2.Location = new System.Drawing.Point(16, 40);
			this.label2.Name = "label2";
			this.label2.Size = new System.Drawing.Size(64, 16);
			this.label2.TabIndex = 0;
			this.label2.Text = "File path:";
			// 
			// cmdEditMatch
			// 
			this.cmdEditMatch.Location = new System.Drawing.Point(304, 128);
			this.cmdEditMatch.Name = "cmdEditMatch";
			this.cmdEditMatch.Size = new System.Drawing.Size(75, 23);
			this.cmdEditMatch.TabIndex = 1;
			this.cmdEditMatch.Tag = "Allows you to edit the properties of the selected search/replace/highlight operat" +
			"ion.";
			this.cmdEditMatch.Text = "Edit...";
			this.cmdEditMatch.Click += new System.EventHandler(this.CmdEditMatchClick);
			// 
			// cmdDeleteMatch
			// 
			this.cmdDeleteMatch.Location = new System.Drawing.Point(384, 128);
			this.cmdDeleteMatch.Name = "cmdDeleteMatch";
			this.cmdDeleteMatch.Size = new System.Drawing.Size(75, 23);
			this.cmdDeleteMatch.TabIndex = 1;
			this.cmdDeleteMatch.Tag = "Allows you to delete the selected search/replace/highlight operation.";
			this.cmdDeleteMatch.Text = "&Delete...";
			this.cmdDeleteMatch.Click += new System.EventHandler(this.CmdDeleteMatchClick);
			// 
			// lvwMatches
			// 
			this.lvwMatches.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
									this.colMatch,
									this.colActions});
			this.lvwMatches.FullRowSelect = true;
			this.lvwMatches.HideSelection = false;
			this.lvwMatches.Location = new System.Drawing.Point(16, 24);
			this.lvwMatches.Name = "lvwMatches";
			this.lvwMatches.Size = new System.Drawing.Size(440, 97);
			this.lvwMatches.TabIndex = 0;
			this.lvwMatches.Tag = "A list of all the search/replace/highlight operations you want to do on this file" +
			".  These allow you to remove certain lines, replace parts of lines, and colour t" +
			"he lines in as the log file grows.";
			this.lvwMatches.UseCompatibleStateImageBehavior = false;
			this.lvwMatches.View = System.Windows.Forms.View.Details;
			this.lvwMatches.SelectedIndexChanged += new System.EventHandler(this.LvwMatchesSelectedIndexChanged);
			this.lvwMatches.DoubleClick += new System.EventHandler(this.LvwMatchesDoubleClick);
			// 
			// colActions
			// 
			this.colActions.Text = "Actions";
			this.colActions.Width = 294;
			// 
			// label1
			// 
			this.label1.Location = new System.Drawing.Point(16, 24);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(80, 16);
			this.label1.TabIndex = 0;
			this.label1.Text = "Display name:";
			// 
			// cmdCancel
			// 
			this.cmdCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
			this.cmdCancel.Location = new System.Drawing.Point(520, 48);
			this.cmdCancel.Name = "cmdCancel";
			this.cmdCancel.Size = new System.Drawing.Size(104, 23);
			this.cmdCancel.TabIndex = 6;
			this.cmdCancel.Tag = "Closes the dialog box, undoing any changes you have made.";
			this.cmdCancel.Text = "&Cancel";
			this.cmdCancel.Click += new System.EventHandler(this.CmdCancelClick);
			// 
			// optSSH
			// 
			this.optSSH.Location = new System.Drawing.Point(312, 56);
			this.optSSH.Name = "optSSH";
			this.optSSH.Size = new System.Drawing.Size(56, 16);
			this.optSSH.TabIndex = 1;
			this.optSSH.Tag = "Choose this option if you need to use telnet to access the log file (e.g. it resi" +
			"des on a unix machine)";
			this.optSSH.Text = "SSH";
			this.optSSH.CheckedChanged += new System.EventHandler(this.OptSSHCheckedChanged);
			// 
			// optLocal
			// 
			this.optLocal.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
			this.optLocal.Location = new System.Drawing.Point(112, 56);
			this.optLocal.Name = "optLocal";
			this.optLocal.Size = new System.Drawing.Size(120, 16);
			this.optLocal.TabIndex = 1;
			this.optLocal.Tag = "Choose this option if the log file you want to view resides on your local machine" +
			" or on a Windows network.";
			this.optLocal.Text = "Local Windows file";
			this.optLocal.CheckedChanged += new System.EventHandler(this.OptLocalCheckedChanged);
			// 
			// cmdMatchUp
			// 
			this.cmdMatchUp.Location = new System.Drawing.Point(16, 128);
			this.cmdMatchUp.Name = "cmdMatchUp";
			this.cmdMatchUp.Size = new System.Drawing.Size(48, 23);
			this.cmdMatchUp.TabIndex = 1;
			this.cmdMatchUp.Tag = "Moves the selected replacement/highlight operation up in the list.";
			this.cmdMatchUp.Text = "Up";
			this.cmdMatchUp.Click += new System.EventHandler(this.CmdMatchUpClick);
			// 
			// groupBox1
			// 
			this.groupBox1.Controls.Add(this.cmdDeleteMatch);
			this.groupBox1.Controls.Add(this.lvwMatches);
			this.groupBox1.Controls.Add(this.cmdEditMatch);
			this.groupBox1.Controls.Add(this.cmdNewMatch);
			this.groupBox1.Controls.Add(this.cmdMatchUp);
			this.groupBox1.Controls.Add(this.cmdMatchDown);
			this.groupBox1.Location = new System.Drawing.Point(16, 517);
			this.groupBox1.Name = "groupBox1";
			this.groupBox1.Size = new System.Drawing.Size(472, 168);
			this.groupBox1.TabIndex = 2;
			this.groupBox1.TabStop = false;
			this.groupBox1.Text = "Replacements/highlighting";
			// 
			// cmdNewMatch
			// 
			this.cmdNewMatch.Location = new System.Drawing.Point(224, 128);
			this.cmdNewMatch.Name = "cmdNewMatch";
			this.cmdNewMatch.Size = new System.Drawing.Size(75, 23);
			this.cmdNewMatch.TabIndex = 1;
			this.cmdNewMatch.Tag = "Creates a new search/replace/highlight operation.";
			this.cmdNewMatch.Text = "&New...";
			this.cmdNewMatch.Click += new System.EventHandler(this.CmdNewMatchClick);
			// 
			// optTelnet
			// 
			this.optTelnet.Location = new System.Drawing.Point(240, 56);
			this.optTelnet.Name = "optTelnet";
			this.optTelnet.Size = new System.Drawing.Size(64, 16);
			this.optTelnet.TabIndex = 1;
			this.optTelnet.Tag = "Choose this option if you need to use telnet to access the log file (e.g. it resi" +
			"des on a unix machine)";
			this.optTelnet.Text = "Telnet";
			this.optTelnet.CheckedChanged += new System.EventHandler(this.OptTelnetCheckedChanged);
			// 
			// cmdOK
			// 
			this.cmdOK.Location = new System.Drawing.Point(520, 16);
			this.cmdOK.Name = "cmdOK";
			this.cmdOK.Size = new System.Drawing.Size(104, 23);
			this.cmdOK.TabIndex = 5;
			this.cmdOK.Tag = "Closes the dialog box and temporarily saves any changes you have made.";
			this.cmdOK.Text = "&OK";
			this.cmdOK.Click += new System.EventHandler(this.CmdOKClick);
			// 
			// label6
			// 
			this.label6.Location = new System.Drawing.Point(16, 56);
			this.label6.Name = "label6";
			this.label6.Size = new System.Drawing.Size(96, 24);
			this.label6.TabIndex = 0;
			this.label6.Text = "Connection type:";
			// 
			// groupBox3
			// 
			this.groupBox3.Controls.Add(this.txtDisplayName);
			this.groupBox3.Controls.Add(this.groupBox1);
			this.groupBox3.Controls.Add(this.optLocal);
			this.groupBox3.Controls.Add(this.label1);
			this.groupBox3.Controls.Add(this.optTelnet);
			this.groupBox3.Controls.Add(this.optSSH);
			this.groupBox3.Controls.Add(this.label6);
			this.groupBox3.Controls.Add(this.grpTelnet);
			this.groupBox3.Controls.Add(this.grpLocal);
			this.groupBox3.Location = new System.Drawing.Point(8, 8);
			this.groupBox3.Name = "groupBox3";
			this.groupBox3.Size = new System.Drawing.Size(504, 700);
			this.groupBox3.TabIndex = 7;
			this.groupBox3.TabStop = false;
			// 
			// EditLogFileForm
			// 
			this.AcceptButton = this.cmdOK;
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.CancelButton = this.cmdCancel;
			this.ClientSize = new System.Drawing.Size(634, 723);
			this.Controls.Add(this.cmdImport);
			this.Controls.Add(this.groupBox3);
			this.Controls.Add(this.cmdCancel);
			this.Controls.Add(this.cmdOK);
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
			this.MaximizeBox = false;
			this.MinimizeBox = false;
			this.Name = "EditLogFileForm";
			this.ShowInTaskbar = false;
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
			this.Text = "Edit Log File";
			this.grpTelnet.ResumeLayout(false);
			this.grpTelnet.PerformLayout();
			this.groupBox2.ResumeLayout(false);
			this.grpLocal.ResumeLayout(false);
			this.grpLocal.PerformLayout();
			this.groupBox1.ResumeLayout(false);
			this.groupBox3.ResumeLayout(false);
			this.groupBox3.PerformLayout();
			this.ResumeLayout(false);
		}
		private System.Windows.Forms.Label label8;
		private System.Windows.Forms.TextBox txtPort;
		private System.Windows.Forms.TextBox txtSshPassword;
		private System.Windows.Forms.Label lblSshPassword;
		private System.Windows.Forms.Label lblAuthMechanism;
		private System.Windows.Forms.ComboBox cboAuthMechanism;
		private System.Windows.Forms.TextBox txtRegex;
		private System.Windows.Forms.RadioButton radMultipleMatchesChooseFirst;
		private System.Windows.Forms.RadioButton radMultipleMatchesChooseLast;
		private System.Windows.Forms.RadioButton radMultipleMatchesChooseMostRecent;
		private System.Windows.Forms.Label label7;
		private System.Windows.Forms.CheckBox chkRegex;
		#endregion
		
		
		void CmdImportClick(object sender, System.EventArgs e)
		{
			ImportLogFileForm f = new ImportLogFileForm();
			f.ShowDialog();
			
			if (null != f.LogFile)
			{
				this.working_i = LogsetLoader.CloneLogfile(f.LogFile);
				PopulateFields();	
			}
		}
		
		void LvwAutoLoginsSelectedIndexChanged(object sender, System.EventArgs e)
		{
			UpdateButtons();
		}
		
				
		void LvwMatchesSelectedIndexChanged(object sender, System.EventArgs e)
		{
			UpdateButtons();
		}
		
		
		
		void ChkRegexCheckedChanged(object sender, EventArgs e)
		{
			UpdateButtons();
		}
		
		void CboAuthMechanismSelectedIndexChanged(object sender, EventArgs e)
		{
			ShowOrHideFrames();
		}
	}
}
